package com.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AspectByAno {
    @Pointcut("execution(* com.aop.*.*(..))")
    public void myPointByAno(){

    }

    @Before("myPointByAno()")
    //定义前置通知
    public void myBefore(JoinPoint joinPoint) {
        System.out.println("*****myBefore***前置通知");
        System.out.println("aop 目标类==" + joinPoint.getTarget());
        System.out.println("织入方法" + joinPoint.getSignature().getName());
    }

    @AfterReturning("myPointByAno()")
    public void myAfterReturning(JoinPoint joinPoint) {
        System.out.println("*****myAfterReturning***后置返回通知");
        System.out.println("织入方法" + joinPoint.getSignature().getName());
    }

    @Around("myPointByAno()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知开始****");
        Object obj = proceedingJoinPoint.proceed();
        System.out.println("环绕通知结束****");
        return obj;
    }

    @After("myPointByAno()")
    public void myAfter(JoinPoint joinPoint) {
        System.out.println("*****mmyAfter***后置通知");
        System.out.println("织入方法" + joinPoint.getSignature().getName());
    }

    @AfterThrowing(value = "myPointByAno()",throwing = "e")
    public void myException(JoinPoint joinPoint,Throwable e) {
        System.out.println("*****myException***异常通知,出错信息:" + e.getMessage());
    }

}
